package com.netflexitysolutions.amazonws.ec2.internal.operations;

import com.amazonaws.ec2.doc._2009_04_04.AttachVolumeResponseType;
import com.amazonaws.ec2.doc._2009_04_04.DetachVolumeResponseType;
import com.amazonaws.ec2.doc._2009_04_04.DetachVolumeType;
import com.netflexitysolutions.amazonws.ec2.AttachmentInfo;
import com.netflexitysolutions.amazonws.ec2.AttachmentStatus;
import com.netflexitysolutions.amazonws.ec2.EC2;
import com.netflexitysolutions.amazonws.ec2.internal.ModelUtil;

public class DetachVolumeOperation extends OperationExecutor<DetachVolumeType, AttachmentInfo> {
	
	private String volumeId;
	
	private String instanceId;
	
	private String device;
	
	private Boolean force;
	
	public DetachVolumeOperation(EC2 ec2, String volumeId, String instanceId, String device, Boolean force) {
		super(ec2);
		this.volumeId = volumeId;
		this.instanceId = instanceId;
		this.device = device;
		this.force = force;
	}

	@Override
	protected AttachmentInfo call(DetachVolumeType request) {
		request.setDevice(device);
		request.setInstanceId(instanceId);
		request.setVolumeId(volumeId);
		request.setForce(force);
		DetachVolumeResponseType response = getEC2().getService().detachVolume(request);
		return new AttachmentInfo(response.getVolumeId(), response.getInstanceId(), response.getDevice(),
				AttachmentStatus.attachmentStatusForName(response.getStatus()), 
				ModelUtil.toDomainType(response.getAttachTime()));
	}

}
